import {
    createRouter,
    createWebHashHistory
} from "vue-router";

import {
    useUserStore
} from "../stores/user";
// import { huonese } from '../request/login'
import { huonese } from '../request/login'

export const constantRoutes = [
    {
        path: '/', //路径描述
        redirect: '/login' //重定向
        // redirect: '/home'
    },
    {
        path: '/login',
        name: 'login',
        component: () => import('@/views/login/index.vue')
    },
    {
        path: '/home',
        name: 'home',
        component: () => import('@/views/Home/index.vue')
    },
    {
        path: '/homeDetail',
        name: 'homeDetail',
        component: () => import('@/views/homeList/detail.vue')
    },
    {
        path: '/user',
        name: 'user',
        component: () => import('@/views/user/index.vue')
    },
    {
        path: '/homeList',
        name: 'homeList',
        component: () => import('@/views/homeList/index.vue')
    },
    {
        path: '/renovation',
        name: 'renovation',
        component: () => import('@/views/renovation/index.vue')
    },
    {
        path: '/renovation/Detail',
        name: 'renovationDetail',
        component: () => import('@/views/renovation/detail.vue')
    },
    {
        path: '/renovation/update',
        name: 'renovationUpdate',
        component: () => import('@/views/renovation/update.vue')
    },
    {
        path: '/rental',
        name: 'rental',
        component: () => import('@/views/rental/index.vue')
    }, {
        path: '/rentalDetail',
        name: 'rentalDetail',
        component: () => import('@/views/rental/detail.vue')
    },
    {
        path: '/zkDetail',
        name: 'zkDetail',
        component: () => import('@/views/tenant/detail.vue')
    },
    {
        path: '/addReo',
        name: 'addReo',
        component: () => import('@/views/addReo/index.vue')
    },
    {
        path: '/tenant',
        name: 'tenant',
        component: () => import('@/views/tenant/index.vue')
    },
    {
        path: '/tenantDetail',
        name: 'tenantDetail',
        component: () => import('@/views/tenant/detail.vue')
    },
    {
        path: '/tenantHouse',
        name: 'tenantHouse',
        component: () => import('@/views/tenantHouse/index.vue')
    },
    {
        path: '/tenantUpdate',
        name: 'tenantUpdate',
        component: () => import('@/views/rental/update.vue')
    },
    {
        path: '/complaint',
        name: 'complaint',
        component: () => import('@/views/complaint/index.vue')
    },
    {
        path: '/complaint/Detail',
        name: 'complaintDetail',
        component: () => import('@/views/complaint/index.vue')
    },
    {
        path: '/complaint/edit',
        name: 'complaintEdit',
        component: () => import('@/views/complaint/index.vue')
    },
    // （物业人员）装修服务
    {
        path: '/decoration',
        name: 'decoration',
        component: () => import('@/views/decoration/index.vue'),
        meta: {
            title: '装修服务',
            role: '物业人员'
        }
    },
    {
        path: '/decoration/Detail',
        name: 'decorationDetail',
        component: () => import('@/views/decoration/detail.vue'),
        meta: {
            title: '装修服务详情',
            role: '物业人员'
        }
    },
    // 违规投诉
    {
        path: '/violationComplaint',
        name: 'violationComplaint',
        component: () => import('@/views/violationComplaint/index.vue'),
        meta: {
            title: '违规投诉',
            role: '物业人员'
        }
    },
    {
        path: '/violationComplaint/detail',
        name: 'violationComplaintDetail',
        component: () => import('@/views/violationComplaint/detail.vue'),
        meta: {
            title: '违规投诉详情',
            role: '物业人员'
        }
    }
]

const router = createRouter({
    history: createWebHashHistory(),
    routes: constantRoutes
})

// router.beforeEach((to, from, next) => {
//     document.title = '房屋码'
//     huonese().then(() => {
//         alert(`token：${sessionStorage.getItem('token')}`)
//         if (sessionStorage.getItem('token')) {
//             useUserStore().getUserInfo()
//             alert(`获取用户信息：${sessionStorage.getItem('userInfo')}`)
//             next()
//         }
//     })
// })

export default router;